package com.ruoyi.web.controller.data;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.PoEventOpinionRelation;
import com.ruoyi.system.domain.PoPublicOpinion;
import com.ruoyi.system.domain.vo.ExtractInfo;
import com.ruoyi.system.domain.vo.FileUploadVO;
import com.ruoyi.system.service.*;
import com.ruoyi.system.service.impl.EsUtil;
import com.ruoyi.system.service.impl.NlpcUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static com.ruoyi.common.exception.ExceptionCode.BASE_VALID_PARAM;
import static com.ruoyi.web.core.config.SwaggerConfig.DATA_TYPE_MULTIPART_FILE;

/**
 * 数据源管理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/data")
@Api(tags = "数据：数据源管理")
public class FileImportController {


    @Autowired
    private ServerConfig serverConfig;
    @Autowired
    private IPoPublicOpinionService poPublicOpinionService;
    @Autowired
    private IPublicOpinionTopicService poEventOpinionRelationService;
    @Autowired
    private IOpinionSourceFileService opinionSourceFileService;
    @Autowired
    private IOpinionForecastService opinionForecastService;
    @Autowired
    private IPublicOpinionEventsService publicOpinionEventsService;


    /**
     * 上传文件
     */
    @ApiOperation(value = "附件上传", notes = "附件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "附件", dataType = DATA_TYPE_MULTIPART_FILE, allowMultiple = true, required = true),
    })
    @PostMapping(value = "/tenantAvatar/upload")
    public AjaxResult upload(@RequestParam(value = "file") MultipartFile file,
                                  @Validated FileUploadVO attachmentVO) {
        // 忽略路径字段,只处理文件类型
        if (file.isEmpty()) {
            return AjaxResult.error(BASE_VALID_PARAM.build("请上传有效文件").getMsg());
        }
        String path = null;
        try {
            path = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return AjaxResult.success(path);
    }






}
